/**
 * 
 */
package com.dp.behav.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Sunaina.Sharma
 * 
 */
public class WeatherData implements Subject {
	private List<Observer> observerList;
	private float temperature;
	private float humidity;

	/**
	 * 
	 */
	public WeatherData() {
		this.observerList = new ArrayList<Observer>();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.dp.behav.observer.Subject#notifyObservers()
	 */
	public void notifyObservers() {
		for (Observer observer : observerList) {
			observer.update(temperature, humidity);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.dp.behav.observer.Subject#registerObserver(java.util.Observer)
	 */
	public void registerObserver(Observer observer) {
		observerList.add(observer);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.dp.behav.observer.Subject#removeObserver(java.util.Observer)
	 */
	public void removeObserver(Observer observer) {
		observerList.remove(observer);
	}

	/**
	 * This method is invoked when there is change in measurements
	 */
	public void measurementsChanged() {
		notifyObservers();
	}

	/**
	 * @param temp
	 * @param humid
	 */
	public void setMeasurements(float temp, float humid) {
		this.temperature = temp;
		this.humidity = humid;
		measurementsChanged();
	}

}
